
var ERROR='500';
var WRONG='201';
var SUCCESS='200';


$(function(){
	
	$('#submit').click(showTicket);	
	
	
});

function showTicket(){
	console.log(1);
	var postid=$('#post_id').val().trim();
	var data={'postid':postid};
	$.ajax({
			url:'query.do',
			type:'get',	
			data:data,
			datatype:'json',
			success:function(result){
				var obj=eval('('+result+')');
				
				console.log(obj);
				
				var messages=obj.data;
				if(obj.status==WRONG||obj.status==ERROR){
					$('#show_context').empty();
					$('p').html(obj.message);
				}
				if(obj.status==SUCCESS){
					var com=obj.com;
//					console.log(com);
					$('p').html('快递公司:'+com);
				}
				
				showMessage(messages);
			},
			error:function(e){
				alert('通讯失败');
			}
	});

};	
	
function showMessage(messages){
	console.log(messages);
	$('#show_context').empty();
	for(var i=0;i<messages.length;i++){
		var mess=messages[i];
		var time=mess.time;
		var context=mess.context;
		var tr='<tr>'+
					'<td>'+time+'</td>'+
					'<td>&nbsp;:&nbsp;</td>'+
					'<td>'+context+'</td>'+
				'</tr>';
		tr=$(tr);
		$('#show_context').append(tr);
	}
};	
	















